<?php


namespace App\Models\Admin;


use App\Log\AdminImgCategoryLog;

class AdminImgCategory extends Base
{
    const OPERATE_PID = 4;
    const MODEL = 'admin_img_category';

    protected $table = 'admin_img_category';
    protected $guarded = [];
    public $timestamps = false;

    public static function getList()
    {
        $list = self::orderBy('pid','asc')
            ->get();
        if(empty($list))
        {
            return $list;
        }
        $list=self::generateTree($list);
        return $list;
    }

    public static function addLog($pre,$next,$type,$method='')
    {
        $info = AdminOperateModule::where('pid',self::OPERATE_PID)->where('type',$type)->where('model',self::MODEL)->when($method,function ($query)use ($method){
            $query->where('method',$method);
        })->first();
        if (!empty($info)){
            $adminLog = new AdminImgCategoryLog($pre,$next,$info);
            $adminLog->addLog();
        }
    }
}
